package crivia.ecp.carry.em;

import crivia.ecp.carry.html.table.TDCell;
import crivia.ecp.carry.html.table.Table;
import crivia.ecp.carry.html.table.TableRow;
import crivia.txt.sc.RK;

public class E8WorkflowExcelStyleTable extends Table {

	private String TFAK = RK.rk(7);
	private String TFAV = RK.rk(7);
	public TDCell toTitle(TDCell td){
		if (null == td){
			return td;
		}
		td.addAttr(TFAK, TFAV);
		return td;
	}
	
	public E8WorkflowExcelStyleTable(){}
	
	public E8WorkflowExcelStyleTable(String colorBorder , String colorBGTitle){
		this.colorBorder = colorBorder;
		this.colorBGTitle = colorBGTitle;
	}
	
	public E8WorkflowExcelStyleTable(String colorBorder , String colorBGTitle , String colorBG){
		this.colorBorder = colorBorder;
		this.colorBGTitle = colorBGTitle;
		this.colorBG = colorBG;
	}

	protected String colorBorder = "#90badd";
	public String getColorBorder() {
		return colorBorder;
	}
	public E8WorkflowExcelStyleTable setColorBorder(String colorBorder) {
		this.colorBorder = colorBorder;
		return this;
	}
	protected String colorBGTitle = "#e7f3fc";
	public String getColorBGTitle() {
		return colorBGTitle;
	}
	public E8WorkflowExcelStyleTable setColorBGTitle(String colorBGTitle) {
		this.colorBGTitle = colorBGTitle;
		return this;
	}
	protected String colorBG = "#ffffff";
	public String getColorBG() {
		return colorBG;
	}
	public E8WorkflowExcelStyleTable setColorBG(String colorBG) {
		this.colorBG = colorBG;
		return this;
	}
	
	public E8WorkflowExcelStyleTable title(int row , int cell){
		toTitle(getRow(row).getCell(cell));
		return this;
	}
	
	public E8WorkflowExcelStyleTable titleRow(int row , int... skip){
		for (int c = 0; c < getRow(row).getCells().size(); c++){
			boolean isSkip = false;
			for (Integer k : skip){
				if (k == c){
					isSkip = true;
				}
			}
			if (isSkip){
				continue;
			}
			toTitle(getRow(row).getCell(c));
		}
		return this;
	}
	
	public E8WorkflowExcelStyleTable titleColumn(int column , int... skip){
		for (int r = 0; r < getRows().size(); r++){
			boolean isSkip = false;
			for (Integer k : skip){
				if (k == r){
					isSkip = true;
				}
			}
			if (isSkip){
				continue;
			}
			toTitle(getRow(r).getCell(column));
		}
		return this;
	}
	
	@Override
	public String toString() {
		addStyle("border-collapse", "collapse");
		for (TableRow r : getRows()){
			for (TDCell c : r.getCells()){
				c
					.addStyle("height", "30px")
					.addStyle("margin", "0px")
					.addStyle("padding", "0px")
					.addStyle("border", "1px solid "+colorBorder)
					.addStyle("background-color"
						, (TFAV.equals(c.getAttr(TFAK))
							? colorBGTitle : colorBG)
					)
					;
			}
		}
		return super.toString();
	}

}
